<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>

职级 <select name="gradeId">
    <c:forEach items="${gradeList}" var="g">
        <option value="${g.id}">${g.name}</option>
    </c:forEach>


</select><br>

职位描述 <input name="remark"><br>


<button onclick="zxt()">点击展示折线图</button>
<button onclick="zzt()">点击展示柱状图</button>
<button onclick="bing()">点击展示饼图</button>
<button onclick="excel()">导出Excel</button>
<div id="main" style="width: 500px;height: 500px"></div>

</body>

<script>

    function excel() {
        let gradeId = $('[name=gradeId]').val();
        let remark = $('[name=remark]').val();
        location.href = '/excel.do?gradeId='+ gradeId +'&remark=' + remark
    }



    function bing() {
        let gradeId = $('[name=gradeId]').val();
        let remark = $('[name=remark]').val();

        $.ajax({
            url:'/bing.do?gradeId='+ gradeId +'&remark=' + remark,
            success:function (data) {

                console.log(data)

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                const piePatternSrc =
                    '';
                const bgPatternSrc =
                    '';
                const piePatternImg = new Image();
                piePatternImg.src = piePatternSrc;
                const bgPatternImg = new Image();
                bgPatternImg.src = bgPatternSrc;
                option = {
                    backgroundColor: {
                        image: bgPatternImg,
                        repeat: 'repeat'
                    },
                    title: {
                        text: '饼图纹理',
                        textStyle: {
                            color: '#235894'
                        }
                    },
                    tooltip: {},
                    series: [
                        {
                            name: 'pie',
                            type: 'pie',
                            selectedMode: 'single',
                            selectedOffset: 30,
                            clockwise: true,
                            label: {
                                fontSize: 18,
                                color: '#235894'
                            },
                            labelLine: {
                                lineStyle: {
                                    color: '#235894'
                                }
                            },
                            data:data,
                            itemStyle: {
                                opacity: 0.7,
                                color: {
                                    image: piePatternImg,
                                    repeat: 'repeat'
                                },
                                borderWidth: 3,
                                borderColor: '#235894'
                            }
                        }
                    ]
                };

                option && myChart.setOption(option);
            }
        })
    }

    function zzt() {
        let gradeId = $('[name=gradeId]').val();
        let remark = $('[name=remark]').val();

        $.ajax({
            url:'/zxt.do?gradeId='+ gradeId +'&remark=' + remark,
            success:function (data) {

                console.log(data)

                var x = []
                var y = []
                // 定义 y轴的最大值
                var maxY = 0;

                for (let i = 0; i < data.length; i++) {
                    let ydata = data[i].ydata;

                    if (maxY < ydata){
                        maxY = ydata;
                    }
                }

                for (let i = 0; i < data.length; i++) {
                    let xdata = data[i].xdata;
                    x.push(xdata)
                    let ydata = data[i].ydata;


                    if (ydata == maxY){

                        y.push( {
                            value: ydata,
                            itemStyle: {
                                color: '#a90000'
                            }
                        })
                    }else {
                        y.push(ydata)
                    }
                }
                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'bar'
                        }
                    ]
                };

                option && myChart.setOption(option);

            }
        })


    }

    function zxt() {

        let gradeId = $('[name=gradeId]').val();
        let remark = $('[name=remark]').val();

        $.ajax({
            url:'/zxt.do?gradeId='+ gradeId +'&remark=' + remark,
            success:function (data) {

                console.log(data)

                var x = []
                var y = []
                for (let i = 0; i < data.length; i++) {
                    let xdata = data[i].xdata;
                    x.push(xdata)
                    let ydata = data[i].ydata;
                    y.push(ydata)
                }
                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'line',
                            smooth: true
                        }
                    ]
                };

                option && myChart.setOption(option);
            }
        })



    }



</script>
</html>